from flask import Flask, render_template
from flask.views import View
from database import init_db
from user_routes import register_user_routes
from word_routes import register_word_routes
from learn_routes import register_learn_routes

app = Flask(__name__)
app.secret_key = 'moonjacy_base'

# 初始化数据库
init_db()

# 注册用户路由
register_user_routes(app)
# 注册单词路由
register_word_routes(app)
# 注册背单词路由
register_learn_routes(app)

class NavBarView(View):
    methods = ['GET']

    def dispatch_request(self):
        return render_template('navbar.html')

# 注册视图
app.add_url_rule('/navbar', view_func=NavBarView.as_view('navbar'))

# 主页
@app.route('/')
def index():
    return render_template('index.html')

if __name__ == '__main__':
    app.run(debug=True)